# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=hledger-lib
pkgname=haskell-hledger-lib
pkgver=1.28
pkgrel=20
pkgdesc="A reusable library providing the core functionality of hledger"
url="http://hledger.org"
license=("GPL")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-aeson-pretty' 'haskell-ansi-terminal'
         'haskell-blaze-markup' 'haskell-call-stack' 'haskell-cassava'
         'haskell-cassava-megaparsec' 'haskell-cmdargs' 'haskell-data-default' 'haskell-decimal'
         'haskell-doclayout' 'haskell-extra' 'haskell-file-embed' 'haskell-glob'
         'haskell-hashtables' 'haskell-megaparsec' 'haskell-microlens' 'haskell-microlens-th'
         'haskell-parser-combinators' 'haskell-pretty-simple' 'haskell-regex-tdfa' 'haskell-safe'
         'haskell-tabular' 'haskell-tasty' 'haskell-tasty-hunit' 'haskell-timeit' 'haskell-uglymemo'
         'haskell-unordered-containers' 'haskell-utf8-string')
makedepends=('ghc')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('24784233f177931bf77512ba20987a15c5c0996bd4c6b814edca3162419180381c9242d8e47258f8bf9d9b6d6167cd0e4ca1319e0b5c39f797fb433e5bcdf0cb')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
